﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tools.DataAccess.Common;
using Tools.DataAccess.Repository;
using Tools.Model;

namespace Tools.BusinessLogic.Service
{
    public class ServiceBase<TEntity> : IServiceBase<TEntity>
        where TEntity : EntityBase
    {
        protected IRepository<TEntity> _repository;

        public ServiceBase()
        {
            _repository = AppDABase.GetUnitOfWork().GetRepository<TEntity>();
        }

        public void Add(TEntity entity)
        {
            _repository.Add(entity);
        }

        public void Delete(TEntity entity)
        {
            _repository.Delete(entity);
        }

        public void Update(TEntity entity)
        {
            _repository.Update(entity);
        }

        public TEntity GetById(object Id)
        {
            return _repository.GetById(Id);
        }

        //public IEnumerable<TEntity> Get(System.Linq.Expressions.Expression<Func<TEntity, bool>> filter, Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy, string includeProperties)
        //{
        //    return _repository.Get(filter, orderBy, includeProperties);
        //}

        public IEnumerable<TEntity> GetAll()
        {
            return _repository.GetAll();
        }

        public TEntity SingleOrDefault(System.Linq.Expressions.Expression<Func<TEntity, bool>> filter)
        {
            return _repository.SingleOrDefault(filter);
        }

        public int Save()
        {
            return AppDABase.GetUnitOfWork().Save();
        }
    }
}
